package com.atguigui.leetcode1;

import java.util.Arrays;

/**
 * 2611. 老鼠和奶酪
 * Project: leetcode
 * Package: com.atguigui.leetcode1
 * Version: 1.0
 * <p>
 * Created by WJX on 2023/6/7 9:05
 */
public class P2611MiceAndCheese {
    public static void main(String[] args) {
        Solution solution = new P2611MiceAndCheese().new Solution();

    }


    class Solution {
        public int miceAndCheese(int[] reward1, int[] reward2, int k) {
            int ans = 0;
            int n = reward1.length;
            int[] diff = new int[n];
            for (int i = 0; i < n; i++) {
                ans += reward2[i];
                diff[i] = reward1[i] - reward2[i];
            }

            Arrays.sort(diff);
            for (int i = 1; i <= k; i++) {
                ans += diff[n - i];
            }
            return ans;
        }
    }
}
